/**
 * 
 */
package com.feib.stms.service;

import org.springframework.transaction.annotation.Transactional;

import com.feib.stms.dao.TempPaymentDao;
import com.feib.stms.model.BaseTempPayment;
import com.feib.stms.model.TempUploadFile;
import com.feib.stms.model.User;
import com.feib.stms.pagination.PaginatedList;

/**
 * @author Jimmy Liu
 *
 */
@Transactional(readOnly = true)
public interface FileImportorService <K extends TempPaymentDao<T>, T extends BaseTempPayment > 
{
	/**
	 * 檔名檢查
     * 上傳檔案命名規格: <strong>交割日期_券商代號_遠銀分行代號_股票類別_處理類別_檔案序號.txt</strong><br/>
     * 交割日期：<strong>西元年月日(YYYYMMDD)</strong>, ex:20111205<br/>
     * 券商代號：<strong>4碼</strong>, ex: <br/>
     * <ol>
     * <li>218#.亞東總公司</li>
     * <li>2180.亞東-台北</li>
     * <li>2181.亞東-板橋</li>
     * </ol>
     * 遠銀分行代號：<strong>4碼</strong>, ex: 0023.台北襄陽分行
     * 股票類別：
     * <ul>
     * <li>H.一般上市櫃</li>
     * <li>R.興櫃</li>
     * <li>P.調撥</li>
     * </ul>
     * 處理類別：
     * <ul>
     * <li>0.交割股款</li> 
     * <li>6.申購款</li>
     * <li>4.郵寄費及工本費</li>
     * <li>5.未中籤退還款 (P.S.此檔案內容可能會包含”4.郵寄費及工本費”之資料)</li>
     * <li>9.券商轉（折讓）</li>
     * <br/>-------以下當股票類別為(P:調撥)時使用-------<br/>
     * <li>A.一般交割款手續費調撥</li>
     * <li>B.一般交割款調撥</li>
     * <li>C.興櫃交割款手續費調撥</li>
     * <li>D.興櫃交割款調撥</li>
     * <li>E.申購款調撥</li>
     * <li>F.申購退款調撥</li>
     * <li>G.申購手續費調撥</li>
     * <li>H.融資券款項調撥</li>
     * </ul>
     * 檔案序號：<strong>2碼</strong> (從01開始), ex:01, 02
	 * @param tempUploadFile 暫存檔物件，內含檔案名稱
	 * @param uploadUser 上傳檔案的使用者
	 * @param checkErros 檢查不通過的錯誤訊息
	 * @return
	 */
	@Transactional(readOnly = false)
	public TempUploadFile checkFileNameConventions();

	@Transactional(readOnly = false)
	public TempUploadFile checkFileContent();

	public boolean isPassed();

	public void setTempUploadFile(TempUploadFile tempUploadFile);

	public void setUploadUser(User uploadUser);

	@Transactional(readOnly = false)
	public void deleteTempPaymentByTempUploadFilePk();

	/**
	 * 刪除上傳檔案資料<br/>依序刪除下列資料表
	 * <ol>
	 * <li>TEMP_UPLOAD_FILE_ERROR</li>
	 * <li>TEMP_DELIVERY_PAYMENT</li>
	 * <li>TEMP_DELIVERY_PAYMENT_CHK</li>
	 * <li>TEMP_PURCHASE_PAYMENT</li>
	 * <li>TEMP_PURCHASE_RETURN_PAYMENT</li>
	 * <li>TEMP_UPLOAD_FILE</li> 
	 * </ol>
	 * @param pk
	 * @return
	 */
	@Transactional(readOnly = false)
	public int deleteByTempUploadFilePk(Long pk);

	@Transactional(readOnly = false)
	public void moveToUploadFile(Long pk, Integer checkCount, Integer confirmCount, String preDesignatedAccount);
	
	/**
	 * 上傳暫存檔轉入正式區
	 * @param pk
	 * @param checkCount
	 * @param confirmCount
	 * @param oneToTwo 驗資轉交割 flag，只有 Stms2001(交割檔上傳)會用到
	 * @param preDesignatedAccount TODO
	 */
	@Transactional(readOnly = false)
	public void moveToUploadFile(Long pk, Integer checkCount, Integer confirmCount, boolean oneToTwo, String preDesignatedAccount);

	public PaginatedList<T> findPaginatedListByTempUploadFilePk(Long pk,
			PaginatedList<T> paginatedList);
	
	/**
	 * 取得交割款資料上傳 驗資轉交割 的明細資料
	 * @param pk
	 * @param paginatedList
	 * @return
	 */
	public PaginatedList<T> findChkPaginatedListByUploadFilePk(Long pk,
			PaginatedList<T> paginatedList);

}
